#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void printVector(const vector<int>& v)
{
    for(auto& i:v)
    {
        cout << i << " ";
    }
    cout << endl;
}

class Solution {
public:
    int findDuplicate(vector<int>& nums) 
    {
        vector<int> v(nums);
        sort(v.begin(),v.end());
        for(int i = 0; i < nums.size()-2; i++)
        {
            if(v[i] == v[i+1])
            {
                return v[i];
            }
        }
        return 0;
    }
};

int main()
{
    vector<int> v ={3,1,3,4,2};
    Solution s;
    cout << s.findDuplicate(v);
    return 0;
}

